#include "stdafx.h"
#include "JsonData.h"
#include "json/json.h"

#include "CharsetConvert.h"

CString GetJsonString(const Json::Value& value,const string& strKey)
{
	Json::Value sRet = value[strKey.c_str()];
	if (!sRet.isNull() &&sRet.isString())
	{
		return cu2ct(sRet.asCString());
	}

	return _T("");
}

#define TEMPPARSEJASON(x) bool CJsonData::Parse##x(const string& szJson,x##Data& sRet) const\
{\
	Json::Reader	read;\
	Json::Value		root;\
	bool bRet = read.parse(szJson.c_str(),root);\
	if (bRet)\
	{\
		sRet.szCode = GetJsonString(root,"code");\
		sRet.szDescription = GetJsonString(root,"description");\
		return true;\
	}\
	return false;\
}\


int GetJsonInt(const Json::Value& value,const string& strKey)
{
	Json::Value sRet = value[strKey.c_str()];
	if (!sRet.isNull() &&sRet.isInt())
	{
		return sRet.asInt();
	}

	return 0;
}

CJsonData::CJsonData()
{

}

CJsonData::~CJsonData()
{

}

bool CJsonData::ParseUploadFile(const string& szJson,UploadFileData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;
	
	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szFileId = GetJsonString(root,"fileid");
		sRet.szServer = GetJsonString(root,"server");

		return true;
		
	}
	return false;
}

bool CJsonData::ParseGetFileList(const string& szJson,GetFileListData& sRet) const 
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription =GetJsonString(root,"description");
		sRet.szCount = GetJsonString(root,"count");
		Json::Value filelist = root["filelist"];

		if (filelist.isArray())
		{
			Json::Value defaultvalue ;
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0; i < nCount;i++)
			{
				Json::Value child = filelist[i];
				FileListItem sItem;
				sItem.szId = GetJsonString(child,"id");
				sItem.szType= GetJsonString(child,"type");
				sItem.szName = GetJsonString(child,"name");
				sItem.szOwner = GetJsonString(child,"owner");
				sItem.szCreateTime = GetJsonString(child,"createtime");
				sItem.szDelete = GetJsonString(child,"isdelete");
				sItem.szDownUrl = GetJsonString(child,"downurl");
				sItem.szFileSize = GetJsonString(child,"filesize");
				sItem.szIsDir = GetJsonString(child,"isdir");
				sItem.szM3U8  =GetJsonString(child,"m3u8");
				sItem.szMimeType = GetJsonString(child,"mimetype");
				sItem.szPercent = GetJsonString(child,"percent");
				sItem.szSecurity = GetJsonString(child,"security");
				sItem.szSourceHash = GetJsonString(child,"sourcehash");
				sItem.szSourceUrl = GetJsonString(child,"sourceurl");
				sItem.szStatus = GetJsonString(child,"status");
				sItem.szTransHash = GetJsonString(child,"transhash");
				sItem.szTransUrl = GetJsonString(child,"transurl");
				sItem.szPath = GetJsonString(child,"path");
				sItem.szPassword = GetJsonString(child,"password");
				sItem.szThumb = GetJsonString(child,"thumb");
				sItem.szSourceUrlPlay = GetJsonString(child,"sourceurl_play");

				sRet.vFileList.push_back(sItem);
			}
		}
		else
		{
			const Json::Value& child = filelist;
			FileListItem sItem;
			sItem.szId = GetJsonString(child,"id");
			sItem.szType= GetJsonString(child,"type");
			sItem.szName = GetJsonString(child,"name");
			sItem.szOwner = GetJsonString(child,"owner");
			sItem.szCreateTime = GetJsonString(child,"createtime");
			sItem.szDelete = GetJsonString(child,"isdelete");
			sItem.szDownUrl = GetJsonString(child,"downurl");
			sItem.szFileSize = GetJsonString(child,"filesize");
			sItem.szIsDir = GetJsonString(child,"isdir");
			sItem.szM3U8  =GetJsonString(child,"m3u8");
			sItem.szMimeType = GetJsonString(child,"mimetype");
			sItem.szPercent = GetJsonString(child,"percent");
			sItem.szSecurity = GetJsonString(child,"security");
			sItem.szSourceHash = GetJsonString(child,"sourcehash");
			sItem.szSourceUrl = GetJsonString(child,"sourceurl");
			sItem.szStatus = GetJsonString(child,"status");
			sItem.szTransHash = GetJsonString(child,"transhash");
			sItem.szTransUrl = GetJsonString(child,"transurl");
			sItem.szPath = GetJsonString(child,"path");
			sItem.szPassword = GetJsonString(child,"password");
			sItem.szThumb = GetJsonString(child,"thumb");
			sItem.szSourceUrlPlay = GetJsonString(child,"sourceurl_play");

			sRet.vFileList.push_back(sItem);
		}
		return true;

	}
	return false;
}

bool CJsonData::ParseRecommend(const string& szJson,RecommendData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szTotal = GetJsonString(root,"total");
		sRet.szCount = GetJsonString(root,"count");
		sRet.szReqTime = GetJsonString(root,"reqtime");
		
		Json::Value recommend = root["recommend"];
		if (recommend.isArray())
		{
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0 ; i < nCount ; i ++)
			{
				Json::Value child = recommend[i];
				RecommendItem sItem;
				sItem.szId = GetJsonString(child,"id");
				sItem.szResId = GetJsonString(child,"resid");
				sItem.szType = GetJsonString(child,"type");
				sItem.szName = GetJsonString(child,"name");
				sItem.szChildType = GetJsonString(child,"childtype");
				sItem.szImage = GetJsonString(child,"image");
				sItem.szUrl = GetJsonString(child,"url");
				sItem.szRemark = GetJsonString(child,"remark");
				sItem.szDownload = GetJsonString(child,"download");
				sItem.szDesc = GetJsonString(child,"desc");
				sItem.szAddTime = GetJsonString(child,"addtime");
				sItem.szImgDownload = GetJsonString(child,"imgdownload");
				sItem.szPackageName = GetJsonString(child,"packagename");
				sItem.szPictureImages = GetJsonString(child,"images");
				sItem.szSource = GetJsonString(child,"source");
				sItem.szSourceTime = GetJsonString(child,"sourcetime");
				sItem.szThumb = GetJsonString(child,"thumb");
			
				sRet.vRecommendList.push_back(sItem);

			}
			
		}
		else
		{
			const Json::Value& child = recommend;
			RecommendItem sItem;
			sItem.szId = GetJsonString(child,"id");
			sItem.szResId = GetJsonString(child,"resid");
			sItem.szType = GetJsonString(child,"type");
			sItem.szName = GetJsonString(child,"name");
			sItem.szChildType = GetJsonString(child,"childtype");
			sItem.szImage = GetJsonString(child,"image");
			sItem.szUrl = GetJsonString(child,"url");
			sItem.szRemark = GetJsonString(child,"remark");
			sItem.szDownload = GetJsonString(child,"download");
			sItem.szDesc = GetJsonString(child,"desc");
			sItem.szAddTime = GetJsonString(child,"addtime");
			sItem.szImgDownload = GetJsonString(child,"imgdownload");
			sItem.szPackageName = GetJsonString(child,"packagename");
			sItem.szPictureImages = GetJsonString(child,"images");
			sItem.szSource = GetJsonString(child,"source");
			sItem.szSourceTime = GetJsonString(child,"sourcetime");
			sItem.szThumb = GetJsonString(child,"thumb");

			sRet.vRecommendList.push_back(sItem);

		}

		return true;

	}
	return false;
}

bool CJsonData::ParseGetDownload(const string& szJson,GetDownloadData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szCount  =GetJsonString(root,"count");
		sRet.szTotalCount = GetJsonString(root,"totalcount");

		Json::Value download = root["download"];
		if (download.isArray())
		{
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0 ; i < nCount ; i ++)
			{
				Json::Value child = download[i];
				GetDownloadItem sItem;
				sItem.szId = GetJsonString(child,"id");
				sItem.szResId = GetJsonString(child,"resid");
				sItem.szUserId = GetJsonString(child,"userid");
				sItem.szImage = GetJsonString(child,"image");
				sItem.szResType = GetJsonString(child,"restype");
				sItem.szMovieId = GetJsonString(child,"movieid");
				sItem.szResName  =GetJsonString(child,"resname");
				sItem.szResChildType = GetJsonString(child,"reschildtype");
				sItem.szNeedPassword = GetJsonString(child,"needpassword");
				sItem.szAddTime = GetJsonString(child,"addtime");
				sItem.szDelete = GetJsonString(child,"delete");
				sItem.szRemark = GetJsonString(child,"remark");
				sItem.szSize = GetJsonString(child,"size");
				sItem.szAppCode = GetJsonString(child,"appcode");
				sItem.szAddFrom = GetJsonString(child,"addfrom");
				

				sRet.vDownloadList.push_back(sItem);

			}

		}
		else
		{
			const Json::Value& child = download;
			GetDownloadItem sItem;
			sItem.szId = GetJsonString(child,"id");
			sItem.szResId = GetJsonString(child,"resid");
			sItem.szUserId = GetJsonString(child,"userid");
			sItem.szImage = GetJsonString(child,"image");
			sItem.szResType = GetJsonString(child,"restype");
			sItem.szMovieId = GetJsonString(child,"movieid");
			sItem.szResName  =GetJsonString(child,"resname");
			sItem.szResChildType = GetJsonString(child,"reschildtype");
			sItem.szNeedPassword = GetJsonString(child,"needpassword");
			sItem.szAddTime = GetJsonString(child,"addtime");
			sItem.szDelete = GetJsonString(child,"delete");
			sItem.szRemark = GetJsonString(child,"remark");
			sItem.szSize = GetJsonString(child,"size");
			sItem.szAppCode = GetJsonString(child,"appcode");
			sItem.szAddFrom = GetJsonString(child,"addfrom");


			sRet.vDownloadList.push_back(sItem);
		}
		return true;

	}
	return false;
}

bool CJsonData::ParseDetail(const string& szJson,DetailData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szCount  =GetJsonString(root,"count");

		Json::Value detail = root["detail"];
		if (detail.isArray())
		{
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0 ; i < nCount ; i ++)
			{
				Json::Value child = detail[i];
				DetailItem sItem;
				sItem.szId = GetJsonString(child,"id");
				sItem.szResId = GetJsonString(child,"resid");
				sItem.szImage = GetJsonString(child,"image");
				sItem.szAddTime = GetJsonString(child,"addtime");
				sItem.szRemark = GetJsonString(child,"remark");
				sItem.szType = GetJsonString(child,"type");
				sItem.szName = GetJsonString(child,"name");
				sItem.szChildType = GetJsonString(child,"childtype");

				sRet.vDetailList.push_back(sItem);

			}

		}
		else
		{
			const Json::Value& child = detail;
			DetailItem sItem;
			sItem.szId = GetJsonString(child,"id");
			sItem.szResId = GetJsonString(child,"resid");
			sItem.szImage = GetJsonString(child,"image");
			sItem.szAddTime = GetJsonString(child,"addtime");
			sItem.szRemark = GetJsonString(child,"remark");
			sItem.szType = GetJsonString(child,"type");
			sItem.szName = GetJsonString(child,"name");
			sItem.szChildType = GetJsonString(child,"childtype");

			sRet.vDetailList.push_back(sItem);
		}

		return true;

	}
	return false;
}

bool CJsonData::ParseCreateDir(const string& szJson,CreateDirData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szFileId = GetJsonString(root,"fileid");
		sRet.szIsNew = GetJsonString(root,"isnew");
		sRet.szServer = GetJsonString(root,"server");

		return true;

	}
	return false;
}

bool CJsonData::ParseSearch(const string& szJson,SearchData& sRet) const 
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szCount  =GetJsonString(root,"count");

		Json::Value download = root["download"];
		if (download.isArray())
		{
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0 ; i < nCount ; i ++)
			{
				Json::Value child = download[i];
				GetDownloadItem sItem;
				sItem.szId = GetJsonString(child,"id");
				sItem.szResId = GetJsonString(child,"resid");
				sItem.szUserId = GetJsonString(child,"userid");
				sItem.szImage = GetJsonString(child,"image");
				sItem.szResType = GetJsonString(child,"restype");
				sItem.szMovieId = GetJsonString(child,"movieid");
				sItem.szResName  =GetJsonString(child,"resname");
				sItem.szResChildType = GetJsonString(child,"reschildtype");
				sItem.szNeedPassword = GetJsonString(child,"needpassword");
				sItem.szAddTime = GetJsonString(child,"addtime");
				sItem.szDelete = GetJsonString(child,"delete");
				sItem.szRemark = GetJsonString(child,"remark");
				sItem.szSize = GetJsonString(child,"size");
				sItem.szAppCode = GetJsonString(child,"appcode");
				sItem.szAddFrom = GetJsonString(child,"addfrom");


				sRet.vDownloadList.push_back(sItem);

			}

		}
		else
		{
			const Json::Value& child = download;
			GetDownloadItem sItem;
			sItem.szId = GetJsonString(child,"id");
			sItem.szResId = GetJsonString(child,"resid");
			sItem.szUserId = GetJsonString(child,"userid");
			sItem.szImage = GetJsonString(child,"image");
			sItem.szResType = GetJsonString(child,"restype");
			sItem.szMovieId = GetJsonString(child,"movieid");
			sItem.szResName  =GetJsonString(child,"resname");
			sItem.szResChildType = GetJsonString(child,"reschildtype");
			sItem.szNeedPassword = GetJsonString(child,"needpassword");
			sItem.szAddTime = GetJsonString(child,"addtime");
			sItem.szDelete = GetJsonString(child,"delete");
			sItem.szRemark = GetJsonString(child,"remark");
			sItem.szSize = GetJsonString(child,"size");
			sItem.szAppCode = GetJsonString(child,"appcode");
			sItem.szAddFrom = GetJsonString(child,"addfrom");


			sRet.vDownloadList.push_back(sItem);
		}


		Json::Value filelist = root["filelist"];
		if (filelist.isArray())
		{
			Json::Value defaultvalue ;
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0; i < nCount;i++)
			{
				Json::Value child = filelist[i];
				FileListItem sItem;
				sItem.szId = GetJsonString(child,"id");
				sItem.szType= GetJsonString(child,"type");
				sItem.szName = GetJsonString(child,"name");
				sItem.szOwner = GetJsonString(child,"owner");
				sItem.szCreateTime = GetJsonString(child,"createtime");
				sItem.szDelete = GetJsonString(child,"isdelete");
				sItem.szDownUrl = GetJsonString(child,"downurl");
				sItem.szFileSize = GetJsonString(child,"filesize");
				sItem.szIsDir = GetJsonString(child,"isdir");
				sItem.szM3U8  =GetJsonString(child,"m3u8");
				sItem.szMimeType = GetJsonString(child,"mimetype");
				sItem.szPercent = GetJsonString(child,"percent");
				sItem.szSecurity = GetJsonString(child,"security");
				sItem.szSourceHash = GetJsonString(child,"sourcehash");
				sItem.szSourceUrl = GetJsonString(child,"sourceurl");
				sItem.szStatus = GetJsonString(child,"status");
				sItem.szTransHash = GetJsonString(child,"transhash");
				sItem.szTransUrl = GetJsonString(child,"transurl");
				sItem.szPath = GetJsonString(child,"path");
				sItem.szPassword = GetJsonString(child,"password");
				sItem.szThumb = GetJsonString(child,"thumb");
				sItem.szSourceUrlPlay = GetJsonString(child,"sourceurl_play");

				sRet.vFileList.push_back(sItem);
			}
		}
		else
		{
			const Json::Value& child = filelist;
			FileListItem sItem;
			sItem.szId = GetJsonString(child,"id");
			sItem.szType= GetJsonString(child,"type");
			sItem.szName = GetJsonString(child,"name");
			sItem.szOwner = GetJsonString(child,"owner");
			sItem.szCreateTime = GetJsonString(child,"createtime");
			sItem.szDelete = GetJsonString(child,"isdelete");
			sItem.szDownUrl = GetJsonString(child,"downurl");
			sItem.szFileSize = GetJsonString(child,"filesize");
			sItem.szIsDir = GetJsonString(child,"isdir");
			sItem.szM3U8  =GetJsonString(child,"m3u8");
			sItem.szMimeType = GetJsonString(child,"mimetype");
			sItem.szPercent = GetJsonString(child,"percent");
			sItem.szSecurity = GetJsonString(child,"security");
			sItem.szSourceHash = GetJsonString(child,"sourcehash");
			sItem.szSourceUrl = GetJsonString(child,"sourceurl");
			sItem.szStatus = GetJsonString(child,"status");
			sItem.szTransHash = GetJsonString(child,"transhash");
			sItem.szTransUrl = GetJsonString(child,"transurl");
			sItem.szPath = GetJsonString(child,"path");
			sItem.szPassword = GetJsonString(child,"password");
			sItem.szThumb = GetJsonString(child,"thumb");
			sItem.szSourceUrlPlay = GetJsonString(child,"sourceurl_play");

			sRet.vFileList.push_back(sItem);
		}

		Json::Value recommend = root["recommend"];
		if (recommend.isArray())
		{
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0 ; i < nCount ; i ++)
			{
				Json::Value child = recommend[i];
				RecommendItem sItem;
				sItem.szId = GetJsonString(child,"id");
				sItem.szResId = GetJsonString(child,"resid");
				sItem.szType = GetJsonString(child,"type");
				sItem.szName = GetJsonString(child,"name");
				sItem.szChildType = GetJsonString(child,"childtype");
				sItem.szImage = GetJsonString(child,"image");
				sItem.szUrl = GetJsonString(child,"url");
				sItem.szRemark = GetJsonString(child,"remark");
				sItem.szDownload = GetJsonString(child,"download");
				sItem.szDesc = GetJsonString(child,"desc");
				sItem.szAddTime = GetJsonString(child,"addtime");
				sItem.szImgDownload = GetJsonString(child,"imgdownload");
				sItem.szPackageName = GetJsonString(child,"packagename");
				sItem.szPictureImages = GetJsonString(child,"images");
				sItem.szSource = GetJsonString(child,"source");
				sItem.szSourceTime = GetJsonString(child,"sourcetime");
				sItem.szThumb = GetJsonString(child,"thumb");

				sRet.vRecommendList.push_back(sItem);

			}

		}
		else
		{
			const Json::Value& child = recommend;
			RecommendItem sItem;
			sItem.szId = GetJsonString(child,"id");
			sItem.szResId = GetJsonString(child,"resid");
			sItem.szType = GetJsonString(child,"type");
			sItem.szName = GetJsonString(child,"name");
			sItem.szChildType = GetJsonString(child,"childtype");
			sItem.szImage = GetJsonString(child,"image");
			sItem.szUrl = GetJsonString(child,"url");
			sItem.szRemark = GetJsonString(child,"remark");
			sItem.szDownload = GetJsonString(child,"download");
			sItem.szDesc = GetJsonString(child,"desc");
			sItem.szAddTime = GetJsonString(child,"addtime");
			sItem.szImgDownload = GetJsonString(child,"imgdownload");
			sItem.szPackageName = GetJsonString(child,"packagename");
			sItem.szPictureImages = GetJsonString(child,"images");
			sItem.szSource = GetJsonString(child,"source");
			sItem.szSourceTime = GetJsonString(child,"sourcetime");
			sItem.szThumb = GetJsonString(child,"thumb");

			sRet.vRecommendList.push_back(sItem);

		}

		return true;

	}
	return false;
}

bool CJsonData::ParseDataType(const string& szJson,DataTypeData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szCount = GetJsonString(root,"count");

		Json::Value datatype = root["datatype"];
		if (datatype.isArray())
		{
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0 ; i < nCount ; i ++)
			{
				Json::Value child = datatype[i];
				DataTypeItem sItem;
				sItem.nId = GetJsonInt(child,"id");
				sItem.szName = GetJsonString(child,"name");

				sRet.vDataTypeList.push_back(sItem);
			}
		}
		else
		{
			const Json::Value& child = datatype;
			DataTypeItem sItem;
			sItem.nId = GetJsonInt(child,"id");
			sItem.szName = GetJsonString(child,"name");

			sRet.vDataTypeList.push_back(sItem);

		}

		return true;

	}
	return false;
}

bool CJsonData::ParseGetSize(const string& szJson,GetSizeData& sRet) const 
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szUserId = GetJsonString(root,"user_id");
		sRet.szUserName = GetJsonString(root,"username");
		sRet.szNickName = GetJsonString(root,"nickname");
		sRet.szAddress = GetJsonString(root,"address");
		sRet.szTelephone = GetJsonString(root,"telephone");
		sRet.szSex = GetJsonString(root,"sex");
		sRet.szPhoto = GetJsonString(root,"photo");
		sRet.szLastActive = GetJsonString(root,"lastactive");
		sRet.szProductId = GetJsonString(root,"product_id");
		sRet.szProductName = GetJsonString(root,"productname");
		sRet.szStartTime = GetJsonString(root,"start_time");
		sRet.szEndTime = GetJsonString(root,"end_time");
		sRet.szFreeSpace = GetJsonString(root,"freespace");
		sRet.szUsedSpace = GetJsonString(root,"usedspace");
		sRet.szTotalSpace = GetJsonString(root,"totalspace");
		sRet.szSpaceSize = GetJsonString(root,"space_size");
		sRet.szProcessCount = GetJsonString(root,"process_count");
		sRet.szKeepDays = GetJsonString(root,"keep_days");
		sRet.szConvertKeepDays = GetJsonString(root,"convert_keepdays");
		sRet.szPurid = GetJsonString(root,"purid");

		return true;

	}
	return false;
}


bool CJsonData::ParseGetUploadRecord(const string& szJson,GetUploadRecordData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szCount  =GetJsonString(root,"count");
		Json::Value filelist = root["filelist"];

		if (filelist.isArray())
		{
			Json::Value defaultvalue ;
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0; i < nCount;i++)
			{
				Json::Value child = filelist[i];
				FileListItem sItem;
				sItem.szId = GetJsonString(child,"id");
				sItem.szType= GetJsonString(child,"type");
				sItem.szName = GetJsonString(child,"name");
				sItem.szOwner = GetJsonString(child,"owner");
				sItem.szCreateTime = GetJsonString(child,"createtime");
				sItem.szDelete = GetJsonString(child,"isdelete");
				sItem.szDownUrl = GetJsonString(child,"downurl");
				sItem.szFileSize = GetJsonString(child,"filesize");
				sItem.szIsDir = GetJsonString(child,"isdir");
				sItem.szM3U8  =GetJsonString(child,"m3u8");
				sItem.szMimeType = GetJsonString(child,"mimetype");
				sItem.szPercent = GetJsonString(child,"percent");
				sItem.szSecurity = GetJsonString(child,"security");
				sItem.szSourceHash = GetJsonString(child,"sourcehash");
				sItem.szSourceUrl = GetJsonString(child,"sourceurl");
				sItem.szStatus = GetJsonString(child,"status");
				sItem.szTransHash = GetJsonString(child,"transhash");
				sItem.szTransUrl = GetJsonString(child,"transurl");
				sItem.szPath = GetJsonString(child,"path");
				sItem.szPassword = GetJsonString(child,"password");
				sItem.szThumb = GetJsonString(child,"thumb");
				sItem.szSourceUrlPlay = GetJsonString(child,"sourceurl_play");

				sRet.vFileList.push_back(sItem);
			}
		}
		else
		{
			const Json::Value& child = filelist;
			FileListItem sItem;
			sItem.szId = GetJsonString(child,"id");
			sItem.szType= GetJsonString(child,"type");
			sItem.szName = GetJsonString(child,"name");
			sItem.szOwner = GetJsonString(child,"owner");
			sItem.szCreateTime = GetJsonString(child,"createtime");
			sItem.szDelete = GetJsonString(child,"isdelete");
			sItem.szDownUrl = GetJsonString(child,"downurl");
			sItem.szFileSize = GetJsonString(child,"filesize");
			sItem.szIsDir = GetJsonString(child,"isdir");
			sItem.szM3U8  =GetJsonString(child,"m3u8");
			sItem.szMimeType = GetJsonString(child,"mimetype");
			sItem.szPercent = GetJsonString(child,"percent");
			sItem.szSecurity = GetJsonString(child,"security");
			sItem.szSourceHash = GetJsonString(child,"sourcehash");
			sItem.szSourceUrl = GetJsonString(child,"sourceurl");
			sItem.szStatus = GetJsonString(child,"status");
			sItem.szTransHash = GetJsonString(child,"transhash");
			sItem.szTransUrl = GetJsonString(child,"transurl");
			sItem.szPath = GetJsonString(child,"path");
			sItem.szPassword = GetJsonString(child,"password");
			sItem.szThumb = GetJsonString(child,"thumb");
			sItem.szSourceUrlPlay = GetJsonString(child,"sourceurl_play");

			sRet.vFileList.push_back(sItem);
		}
		return true;

	}
	return false;
}

bool CJsonData::ParseTransPercent(const string& szJson,TransPercentData& sRet) const 
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szCount  =GetJsonString(root,"count");
		Json::Value percentlist = root["percentlist"];

		if (percentlist.isArray())
		{
			Json::Value defaultvalue ;
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0; i < nCount;i++)
			{
				Json::Value child = percentlist[i];
				TransPercentItem sItem;
				sItem.szId = GetJsonString(child,"id");
				sItem.szType= GetJsonString(child,"type");
				sItem.szName = GetJsonString(child,"name");
				sItem.szOwner = GetJsonString(child,"owner");
				sItem.szStatus = GetJsonString(child,"status");
				sItem.szM3U8  =GetJsonString(child,"m3u8");
				sItem.szWidth = GetJsonString(child,"width");
				sItem.szPercent = GetJsonString(child,"percent");
				sItem.szTransUrl = GetJsonString(child,"transurl");
			
				sRet.vTransPercentList.push_back(sItem);
			}
		}
		else
		{
			const Json::Value& child = percentlist;
			TransPercentItem sItem;
			sItem.szId = GetJsonString(child,"id");
			sItem.szType= GetJsonString(child,"type");
			sItem.szName = GetJsonString(child,"name");
			sItem.szOwner = GetJsonString(child,"owner");
			sItem.szStatus = GetJsonString(child,"status");
			sItem.szM3U8  =GetJsonString(child,"m3u8");
			sItem.szWidth = GetJsonString(child,"width");
			sItem.szPercent = GetJsonString(child,"percent");
			sItem.szTransUrl = GetJsonString(child,"transurl");

			sRet.vTransPercentList.push_back(sItem);
		}
		return true;

	}
	return false;
}


bool CJsonData::ParseHDPlay(const string& szJson,HDPlayData& sRet) const 
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szTitle = GetJsonString(root,"title");
		sRet.szSeries = GetJsonString(root,"series");
		sRet.szPlayUrl = GetJsonString(root,"playurl");
		sRet.szContentHash = GetJsonString(root,"content_hash");
		sRet.szPPcip = GetJsonString(root,"ppcip");
		sRet.szFileSize = GetJsonString(root,"filesize");
		sRet.szMovieId = GetJsonString(root,"movieid");
		sRet.szVideoId = GetJsonString(root,"videoid");
		sRet.szCloudPath = GetJsonString(root,"cloudpath");

		return true;

	}
	return false;
}

bool CJsonData::ParseMovieDetail(const string& szJson,MovieDetailData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		
		Json::Value	movielist=root["movie_list"];
		Json::Value movieitem=movielist["movie_item"];
		if (movieitem.isArray())
		{
			int nSize = movieitem.size();
			for (int i = 0; i < nSize;i++)
			{
				Json::Value child = movieitem[i];
				MovieDetailItem sItem;
				sItem.szMovieId = GetJsonString(child,"MovieID");
				sItem.szMovieName = GetJsonString(child,"MovieName");
				sItem.szAlias = GetJsonString(child,"Alias");
				sItem.szTypeId = GetJsonString(child,"TypeID");
				sItem.szDramaType = GetJsonString(child,"DramaType");
				sItem.szDrama = GetJsonString(child,"Drama");
				sItem.szTimeSpan = GetJsonString(child,"TimeSpan");
				sItem.szDirector = GetJsonString(child,"Director");
				sItem.szActor = GetJsonString(child,"Actor");
				sItem.szAreaId = GetJsonString(child,"AreaID");
				sItem.szAreaName = GetJsonString(child,"AreaName");
				sItem.szPublishAge = GetJsonString(child,"PublishAge");
				sItem.szPoster = GetJsonString(child,"Poster");
				sItem.szPoster2 = GetJsonString(child,"Poster2");
				sItem.szHost  =GetJsonString(child,"Host");
				sItem.szAuthor  =GetJsonString(child,"Author");
				sItem.szCount = GetJsonString(child,"count");
				sItem.szDescription = GetJsonString(child,"Description");
				sItem.szCommentary = GetJsonString(child,"Commentary");
				sItem.szTags = GetJsonString(child,"Tags");
				sItem.szMark = GetJsonString(child,"Mark");

				sRet.vMovieDetailList.push_back(sItem);
			}
		}
		else
		{
			const Json::Value& child = movieitem;
			MovieDetailItem sItem;
			sItem.szMovieId = GetJsonString(child,"MovieID");
			sItem.szMovieName = GetJsonString(child,"MovieName");
			sItem.szAlias = GetJsonString(child,"Alias");
			sItem.szTypeId = GetJsonString(child,"TypeID");
			sItem.szDramaType = GetJsonString(child,"DramaType");
			sItem.szDrama = GetJsonString(child,"Drama");
			sItem.szTimeSpan = GetJsonString(child,"TimeSpan");
			sItem.szDirector = GetJsonString(child,"Director");
			sItem.szActor = GetJsonString(child,"Actor");
			sItem.szAreaId = GetJsonString(child,"AreaID");
			sItem.szAreaName = GetJsonString(child,"AreaName");
			sItem.szPublishAge = GetJsonString(child,"PublishAge");
			sItem.szPoster = GetJsonString(child,"Poster");
			sItem.szPoster2 = GetJsonString(child,"Poster2");
			sItem.szHost  =GetJsonString(child,"Host");
			sItem.szAuthor  =GetJsonString(child,"Author");
			sItem.szCount = GetJsonString(child,"count");
			sItem.szDescription = GetJsonString(child,"Description");
			sItem.szCommentary = GetJsonString(child,"Commentary");
			sItem.szTags = GetJsonString(child,"Tags");
			sItem.szMark = GetJsonString(child,"Mark");

			sRet.vMovieDetailList.push_back(sItem);
		}




		Json::Value	httplist=root["http_list"];
		Json::Value httpcount = root["http_count"];
		if (!httpcount.isNull())
		{
			sRet.szHttpCount = httpcount.asCString();
		}
		Json::Value httpitem=movielist["http_item"];
		if (httpitem.isArray())
		{
			int nSize = httpitem.size();
			for (int i = 0; i < nSize;i++)
			{
				Json::Value child = httpitem[i];
				MovieDetailHttpItem sItem;
				sItem.szMid = GetJsonString(child,"mid");
				sItem.szTitle = GetJsonString(child,"title");
				sItem.szUrl = GetJsonString(child,"url");
				sItem.szTag = GetJsonString(child,"tag");
				sItem.szMD5Url = GetJsonString(child,"md5url");
				sItem.szTagName = GetJsonString(child,"tagname");
				sItem.szSwfUrl = GetJsonString(child,"swfurl");
				sItem.szSeries = GetJsonString(child,"series");

				sRet.vMovieDetailHttpList.push_back(sItem);
			}
		}
		else
		{
			const Json::Value& child = httpitem;
			MovieDetailHttpItem sItem;
			sItem.szMid = GetJsonString(child,"mid");
			sItem.szTitle = GetJsonString(child,"title");
			sItem.szUrl = GetJsonString(child,"url");
			sItem.szTag = GetJsonString(child,"tag");
			sItem.szMD5Url = GetJsonString(child,"md5url");
			sItem.szTagName = GetJsonString(child,"tagname");
			sItem.szSwfUrl = GetJsonString(child,"swfurl");
			sItem.szSeries = GetJsonString(child,"series");

			sRet.vMovieDetailHttpList.push_back(sItem);
		}
		return true;

	}
	return false;
}

bool CJsonData::ParseSearchData(const string& szJson,SearchDataData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szCount = GetJsonString(root,"count");

		Json::Value recommend = root["recommend"];
		if (recommend.isArray())
		{
			int nCount = StrToInt(sRet.szCount);
			for (int i = 0 ; i < nCount ; i ++)
			{
				Json::Value child = recommend[i];
				RecommendItem sItem;
				sItem.szId = GetJsonString(child,"id");
				sItem.szResId = GetJsonString(child,"resid");
				sItem.szType = GetJsonString(child,"type");
				sItem.szName = GetJsonString(child,"name");
				sItem.szChildType = GetJsonString(child,"childtype");
				sItem.szImage = GetJsonString(child,"image");
				sItem.szUrl = GetJsonString(child,"url");
				sItem.szRemark = GetJsonString(child,"remark");
				sItem.szDownload = GetJsonString(child,"download");
				sItem.szDesc = GetJsonString(child,"desc");
				sItem.szAddTime = GetJsonString(child,"addtime");
				sItem.szImgDownload = GetJsonString(child,"imgdownload");
				sItem.szPackageName = GetJsonString(child,"packagename");
				sItem.szPictureImages = GetJsonString(child,"images");
				sItem.szSource = GetJsonString(child,"source");
				sItem.szSourceTime = GetJsonString(child,"sourcetime");
				sItem.szThumb = GetJsonString(child,"thumb");

				sRet.vRecommendList.push_back(sItem);

			}

		}
		else
		{
			const Json::Value& child = recommend;
			RecommendItem sItem;
			sItem.szId = GetJsonString(child,"id");
			sItem.szResId = GetJsonString(child,"resid");
			sItem.szType = GetJsonString(child,"type");
			sItem.szName = GetJsonString(child,"name");
			sItem.szChildType = GetJsonString(child,"childtype");
			sItem.szImage = GetJsonString(child,"image");
			sItem.szUrl = GetJsonString(child,"url");
			sItem.szRemark = GetJsonString(child,"remark");
			sItem.szDownload = GetJsonString(child,"download");
			sItem.szDesc = GetJsonString(child,"desc");
			sItem.szAddTime = GetJsonString(child,"addtime");
			sItem.szImgDownload = GetJsonString(child,"imgdownload");
			sItem.szPackageName = GetJsonString(child,"packagename");
			sItem.szPictureImages = GetJsonString(child,"images");
			sItem.szSource = GetJsonString(child,"source");
			sItem.szSourceTime = GetJsonString(child,"sourcetime");
			sItem.szThumb = GetJsonString(child,"thumb");

			sRet.vRecommendList.push_back(sItem);

		}

		return true;

	}
	return false;
}


bool CJsonData::ParseChannelScheduleQuery(const string& szJson,ChannelScheduleQueryData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		Json::Value body = root["body"];
		Json::Value result = body["result"];

		//sRet.strCode = GetJsonString(result,"code");
		sRet.nCode = GetJsonInt(result,"code");
		sRet.strDescription = GetJsonString(result,"description");

		Json::Value channels = body["channels"];

		if (channels.isArray())
		{
			Json::Value child ;
			int i = 0;
			do 
			{
				child = channels[i++];
				if (!child.isNull())
				{
					D2_17_Channel sItem;
					sItem.strTitleFull = GetJsonString(child,"titleFull");
					sItem.strChannelCode = GetJsonString(child,"channelCode");
					sItem.nType = (D2_17_Type)StrToInt(GetJsonString(child,"type"));
					sItem.nStatus = StrToInt(GetJsonString(child,"status"));

					Json::Value physicalChannels=child["physicalChannels"];
					if (physicalChannels.isArray())
					{
						Json::Value child2;
						int i2=0;
						do 
						{
							child2 = physicalChannels[i2++];
							if (!child2.isNull())
							{
								D2_17_PhysicalChannel sItem2;
								sItem2.strAssetID = GetJsonString(child2,"assetID");
								sItem2.strEncodingProfile = GetJsonString(child2,"encodingProfile");
								sItem2.strVideoCodec = GetJsonString(child2,"videoCodec");
								sItem2.strAudioCodec = GetJsonString(child2,"audioCodec");
								sItem2.strHDFlag = GetJsonString(child2,"hDFlag");
								sItem2.strChannelID = GetJsonString(child2,"channelID");
								sItem2.strBitRate = GetJsonString(child2,"bitRate");
								sItem2.strMineType = GetJsonString(child2,"mimeType");

								sItem.vPhysicalChannels.push_back(sItem2);
							}

						} while (!child2.isNull());
					}

					Json::Value assetPrograms = child["assetPrograms"];
					if (assetPrograms.isArray())
					{
						Json::Value child3 ;
						int i3=0;

						do 
						{
							child3 = assetPrograms[i3++];
							if (!child3.isNull())
							{
								D2_17_AssetProgram sItem3;
								sItem3.strAssetID = GetJsonString(child3,"assetID");
								sItem3.strStartDateTime =GetJsonString(child3,"startDateTime");
								sItem3.strEndDateTime = GetJsonString(child3,"endDateTime");
								sItem3.strProgramName = GetJsonString(child3,"programName");
								sItem3.strDescription = GetJsonString(child3,"description");
								sItem3.strDuration = GetJsonString(child3,"duration");
								sItem3.strChannelID = GetJsonString(child3,"channelID");
								sItem3.strCategory = GetJsonString(child3,"category");
								sItem3.strStatus = GetJsonString(child3,"status");


								sItem.vAssetPrograms.push_back(sItem3);
							}
						} while (!child3.isNull());
					}
					
					sRet.vChannels.push_back(sItem);
				}


			} while (!child.isNull());
		}

		return true;
	}

	return false;
}

bool CJsonData::ParseUserPlayHistoryQuery(const string& szJson,UserPlayHistoryQueryData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		Json::Value body = root["body"];
		Json::Value result = body["result"];

		//sRet.strCode = GetJsonString(result,"code");
		sRet.nCode = GetJsonInt(result,"code");
		sRet.strDescription = GetJsonString(result,"description");

		Json::Value histories = body["histories"];

		if (histories.isArray())
		{
			Json::Value child;
			int i = 0 ;
			do 
			{
				child = histories[i++];
				if (!child.isNull())
				{
					D2_18_History sItem;
					sItem.strAssetId = GetJsonString(child,"assetId");
					sItem.strAssetName = GetJsonString(child,"assetName");
					sItem.strAssetType = GetJsonString(child,"assetType");
					sItem.strRecordType = GetJsonString(child,"recordTime");
					sItem.strSourceSystem = GetJsonString(child,"sourceSystem");
					sItem.strUrl = GetJsonString(child,"url");
					sItem.strSupportCodec = GetJsonString(child,"supportCodec");
					sItem.strBreakPoint = GetJsonString(child,"breakPoint");
					sItem.strSiteCode = GetJsonString(child,"siteCode");
					sItem.strFolderCode = GetJsonString(child,"folderCode");

					sRet.vHistories.push_back(sItem);
				}
			} while (!child.isNull());
		}


		return true;
	}
	return false;
}


bool CJsonData::ParseISpaceContentDetailQuery(const string& szJson,ISpaceContentDetailQueryData& sRet) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		Json::Value body = root["body"];
		Json::Value result = body["result"];

		//sRet.strCode = GetJsonString(result,"code");
		sRet.nCode = GetJsonInt(result,"code");
		sRet.strDescription = GetJsonString(result,"description");

		Json::Value contents = body["contents"];

		if (contents.isArray())
		{
			Json::Value child;
			int i=0;
			do 
			{
				child = contents[i++];
				if (!child.isNull())
				{
					D2_19_Content sItem;
					sItem.strContentID = GetJsonString(child,"contentID");
					sItem.strContentName = GetJsonString(child,"contentName");
					sItem.strPlayUrl = GetJsonString(child,"playUrl");
					sItem.strSupportCode = GetJsonString(child,"supportCodec");
					sItem.strImageUrl = GetJsonString(child,"imageUrl");
					sItem.strActor = GetJsonString(child,"actor");
					sItem.strDirector = GetJsonString(child,"director");
					sItem.strShowType = GetJsonString(child,"showType");
					sItem.strSummaryMedium = GetJsonString(child,"summaryMedium");
					sItem.strSummaryShort =GetJsonString(child,"summaryShort");
					sItem.strCategory = GetJsonString(child,"category");
					sItem.strKeyword = GetJsonString(child,"keyword");
					sItem.nBreakPoint = GetJsonInt(child,"breakPoint");

					sRet.vContents.push_back(sItem);
				}
			} while (!child.isNull());
		}


		return true;
	}

	return false;
}


TEMPPARSEJASON(MoveFile)
TEMPPARSEJASON(DeleteFile)
TEMPPARSEJASON(RecoverFile)
TEMPPARSEJASON(ClearRecycler)
TEMPPARSEJASON(SetFilePasswd)
//TEMPPARSEJASON(GetFileList)
TEMPPARSEJASON(TransCode)
//TEMPPARSEJASON(Recommend)
TEMPPARSEJASON(AddDownload)
//TEMPPARSEJASON(GetDownload)
TEMPPARSEJASON(MergeDownload)
TEMPPARSEJASON(DepartDownload)
//TEMPPARSEJASON(Detail)
//TEMPPARSEJASON(CreateDir)
//TEMPPARSEJASON(Search)
//TEMPPARSEJASON(DataType)
//TEMPPARSEJASON(GetSize)
TEMPPARSEJASON(DelDownload)
TEMPPARSEJASON(RenameDownload)
//TEMPPARSEJASON(GetUploadRecord)
//TEMPPARSEJASON(TransPercent)
TEMPPARSEJASON(AddYunDownload)
TEMPPARSEJASON(GetOffDownload)
TEMPPARSEJASON(OnlineOrder)
TEMPPARSEJASON(ResetFilePasswd)
TEMPPARSEJASON(ApkDown)
TEMPPARSEJASON(LoginStat)
TEMPPARSEJASON(DetailStat)
//TEMPPARSEJASON(HDPlay)
//TEMPPARSEJASON(MovieDetail)
TEMPPARSEJASON(ThirdPartTransCode)
TEMPPARSEJASON(ThirdPartHttpCTS)
//TEMPPARSEJASON(SearchData)



void CJsonData::Test(const string& szJson) const
{
	Json::Reader	read;	
	Json::Value		root;

	bool bRet = read.parse(szJson.c_str(),root); 

	if (bRet)
	{
		/*sRet.szCode = GetJsonString(root,"code");
		sRet.szDescription = GetJsonString(root,"description");
		sRet.szFileId = GetJsonString(root,"fileid");
		sRet.szServer = GetJsonString(root,"server");*/

		if (root.isArray())
		{
			Json::Value		child;
			int i=0;
			do 
			{
				child = root[i++];
				CString strAppId = GetJsonString(child,"AppId");
				CString strCategoryId = GetJsonString(child,"CategoryId");
			} while (!child.isNull());
		}

	}
	
}